package o;

import android.text.Layout.Alignment;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import com.huawei.hwphy2d.physical.util.BarrierParameters;
import com.huawei.updatesdk.service.otaupdate.UpdateStatusCode.DialogButton;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import o.ah.g;

public final class ajo extends ajp {
    private static final int[] ʻ = new int[]{195, 227, 205, 204, 236, 210, 242, 213, 245, 123, 125, 92, 94, 95, 124, 126, 196, 228, 214, 246, 223, 165, 164, 9474, 197, 229, 216, 248, 9484, 9488, 9492, 9496};
    private static final int[] ʼ = new int[]{193, 201, 211, 218, 220, 252, 8216, 161, 42, 39, 8212, 169, 8480, 8226, 8220, 8221, 192, 194, 199, 200, 202, 203, 235, 206, 207, 239, 212, 217, 249, 219, 171, 187};
    private static final int[] ˊ = new int[]{-1, -16711936, -16776961, -16711681, -65536, -256, -65281};
    private static final int[] ˋ = new int[]{11, 1, 3, 12, 14, 5, 7, 9};
    private static final int[] ˎ = new int[]{0, 4, 8, 12, 16, 20, 24, 28};
    private static final int[] ˏ = new int[]{174, 176, 189, 191, 8482, 162, 163, 9834, 224, 32, 232, 226, 234, 238, 244, 251};
    private static final int[] ॱ = new int[]{32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 225, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 233, 93, 237, 243, 250, 97, 98, 99, 100, DialogButton.CONFIRM, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, g.ॱˍ, 121, 122, 231, 247, 209, 241, 9632};
    private byte ʻॱ;
    private final int ʽ;
    private final ArrayList<e> ˊॱ = new ArrayList();
    private int ˋॱ;
    private List<Cue> ˏॱ;
    private e ͺ = new e(0, 4);
    private List<Cue> ॱˊ;
    private int ॱˋ;
    private boolean ॱˎ;
    private final anc ॱॱ = new anc();
    private byte ॱᐝ;
    private final int ᐝ;

    static class e {
        private int ʽ;
        private final List<SpannableString> ˊ = new ArrayList();
        private final StringBuilder ˋ = new StringBuilder();
        private final List<b> ˎ = new ArrayList();
        private int ˏ;
        private int ॱ;
        private int ॱॱ;
        private int ᐝ;

        static class b {
            public final int ˊ;
            public int ˎ;
            public final boolean ˏ;

            public b(int i, boolean z, int i2) {
                this.ˊ = i;
                this.ˏ = z;
                this.ˎ = i2;
            }
        }

        public e(int i, int i2) {
            ॱ(i);
            ˊ(i2);
        }

        public void ॱ(int i) {
            this.ʽ = i;
            this.ˎ.clear();
            this.ˊ.clear();
            this.ˋ.setLength(0);
            this.ॱ = 15;
            this.ˏ = 0;
            this.ॱॱ = 0;
        }

        public void ˊ(int i) {
            this.ᐝ = i;
        }

        public boolean ˎ() {
            return this.ˎ.isEmpty() && this.ˊ.isEmpty() && this.ˋ.length() == 0;
        }

        public void ˊ() {
            int length = this.ˋ.length();
            if (length > 0) {
                this.ˋ.delete(length - 1, length);
                int size = this.ˎ.size() - 1;
                while (size >= 0) {
                    b bVar = (b) this.ˎ.get(size);
                    if (bVar.ˎ == length) {
                        bVar.ˎ--;
                        size--;
                    } else {
                        return;
                    }
                }
            }
        }

        public int ˏ() {
            return this.ॱ;
        }

        public void ˋ(int i) {
            this.ॱ = i;
        }

        public void ॱ() {
            this.ˊ.add(ˋ());
            this.ˋ.setLength(0);
            this.ˎ.clear();
            int min = Math.min(this.ᐝ, this.ॱ);
            while (this.ˊ.size() >= min) {
                this.ˊ.remove(0);
            }
        }

        public void ˎ(int i) {
            this.ˏ = i;
        }

        public void ˏ(int i) {
            this.ॱॱ = i;
        }

        public void ˏ(int i, boolean z) {
            this.ˎ.add(new b(i, z, this.ˋ.length()));
        }

        public void ˏ(char c) {
            this.ˋ.append(c);
        }

        public SpannableString ˋ() {
            CharSequence spannableStringBuilder = new SpannableStringBuilder(this.ˋ);
            int length = spannableStringBuilder.length();
            int i = -1;
            int i2 = -1;
            int i3 = 0;
            int i4 = -1;
            Object obj = null;
            int i5 = -1;
            for (int i6 = 0; i6 < this.ˎ.size(); i6++) {
                int i7;
                b bVar = (b) this.ˎ.get(i6);
                boolean z = bVar.ˏ;
                int i8 = bVar.ˊ;
                if (i8 != 8) {
                    obj = i8 == 7 ? 1 : null;
                    if (i8 != 7) {
                        i5 = ajo.ˊ[i8];
                    }
                }
                i8 = bVar.ˎ;
                if (i6 + 1 < this.ˎ.size()) {
                    i7 = ((b) this.ˎ.get(i6 + 1)).ˎ;
                } else {
                    i7 = length;
                }
                if (i8 != i7) {
                    if (i != -1 && !z) {
                        ˊ(spannableStringBuilder, i, i8);
                        i = -1;
                    } else if (i == -1 && z) {
                        i = i8;
                    }
                    if (i2 != -1 && r3 == null) {
                        ˋ(spannableStringBuilder, i2, i8);
                        i2 = -1;
                    } else if (i2 == -1 && r3 != null) {
                        i2 = i8;
                    }
                    if (i5 != i4) {
                        ॱ(spannableStringBuilder, i3, i8, i4);
                        i4 = i5;
                        i3 = i8;
                    }
                }
            }
            if (!(i == -1 || i == length)) {
                ˊ(spannableStringBuilder, i, length);
            }
            if (!(i2 == -1 || i2 == length)) {
                ˋ(spannableStringBuilder, i2, length);
            }
            if (i3 != length) {
                ॱ(spannableStringBuilder, i3, length, i4);
            }
            return new SpannableString(spannableStringBuilder);
        }

        public Cue ʻ() {
            int i;
            int i2 = 2;
            CharSequence spannableStringBuilder = new SpannableStringBuilder();
            for (i = 0; i < this.ˊ.size(); i++) {
                spannableStringBuilder.append((CharSequence) this.ˊ.get(i));
                spannableStringBuilder.append('\n');
            }
            spannableStringBuilder.append(ˋ());
            if (spannableStringBuilder.length() == 0) {
                return null;
            }
            float f;
            int i3;
            int i4;
            int i5 = this.ˏ + this.ॱॱ;
            i = (32 - i5) - spannableStringBuilder.length();
            int i6 = i5 - i;
            if (this.ʽ == 2 && (Math.abs(i6) < 3 || i < 0)) {
                f = 0.5f;
                i3 = 1;
            } else if (this.ʽ != 2 || i6 <= 0) {
                f = ((((float) i5) / 32.0f) * 0.8f) + BarrierParameters.RESTITUTION;
                i3 = 0;
            } else {
                f = ((((float) (32 - i)) / 32.0f) * 0.8f) + BarrierParameters.RESTITUTION;
                i3 = 2;
            }
            if (this.ʽ == 1 || this.ॱ > 7) {
                i4 = (this.ॱ - 15) - 2;
            } else {
                i2 = 0;
                i4 = this.ॱ;
            }
            return new Cue(spannableStringBuilder, Alignment.ALIGN_NORMAL, (float) i4, 1, i2, f, i3, Float.MIN_VALUE);
        }

        public String toString() {
            return this.ˋ.toString();
        }

        private static void ˊ(SpannableStringBuilder spannableStringBuilder, int i, int i2) {
            spannableStringBuilder.setSpan(new UnderlineSpan(), i, i2, 33);
        }

        private static void ˋ(SpannableStringBuilder spannableStringBuilder, int i, int i2) {
            spannableStringBuilder.setSpan(new StyleSpan(2), i, i2, 33);
        }

        private static void ॱ(SpannableStringBuilder spannableStringBuilder, int i, int i2, int i3) {
            if (i3 != -1) {
                spannableStringBuilder.setSpan(new ForegroundColorSpan(i3), i, i2, 33);
            }
        }
    }

    public /* bridge */ /* synthetic */ ajj ʼ() throws SubtitleDecoderException {
        return super.ʼ();
    }

    public /* bridge */ /* synthetic */ ajl ʽ() throws SubtitleDecoderException {
        return super.ʽ();
    }

    public ajo(String str, int i) {
        this.ᐝ = "application/x-mp4-cea-608".equals(str) ? 2 : 3;
        switch (i) {
            case 3:
            case 4:
                this.ʽ = 2;
                break;
            default:
                this.ʽ = 1;
                break;
        }
        ˏ(0);
        ˊॱ();
    }

    public void ˋ() {
        super.ˋ();
        this.ˏॱ = null;
        this.ॱˊ = null;
        ˏ(0);
        ˎ(4);
        ˊॱ();
        this.ॱˎ = false;
        this.ॱᐝ = (byte) 0;
        this.ʻॱ = (byte) 0;
    }

    public void ˎ() {
    }

    protected boolean ˊ() {
        return this.ˏॱ != this.ॱˊ;
    }

    protected aji ʻ() {
        this.ॱˊ = this.ˏॱ;
        return new ajw(this.ˏॱ);
    }

    protected void ˊ(ajl o_ajl) {
        this.ॱॱ.ॱ(o_ajl.ॱ.array(), o_ajl.ॱ.limit());
        boolean z = false;
        boolean z2 = false;
        while (this.ॱॱ.ˊ() >= this.ᐝ) {
            int i;
            if (this.ᐝ == 2) {
                i = -4;
            } else {
                i = (byte) this.ॱॱ.ʽ();
            }
            byte ʽ = (byte) (this.ॱॱ.ʽ() & 127);
            byte ʽ2 = (byte) (this.ॱॱ.ʽ() & 127);
            if ((i & 6) == 4 && ((this.ʽ != 1 || (i & 1) == 0) && ((this.ʽ != 2 || (i & 1) == 1) && !(ʽ == (byte) 0 && ʽ2 == (byte) 0)))) {
                if ((ʽ & 247) == 17 && (ʽ2 & 240) == 48) {
                    this.ͺ.ˏ(ˊ(ʽ2));
                    z2 = true;
                } else if ((ʽ & 246) == 18 && (ʽ2 & 224) == 32) {
                    this.ͺ.ˊ();
                    if ((ʽ & 1) == 0) {
                        this.ͺ.ˏ(ˎ(ʽ2));
                        z2 = true;
                    } else {
                        this.ͺ.ˏ(ʽ(ʽ2));
                        z2 = true;
                    }
                } else if ((ʽ & 224) == 0) {
                    z = ˋ(ʽ, ʽ2);
                    z2 = true;
                } else {
                    this.ͺ.ˏ(ॱ(ʽ));
                    if ((ʽ2 & 224) != 0) {
                        this.ͺ.ˏ(ॱ(ʽ2));
                    }
                    z2 = true;
                }
            }
        }
        if (z2) {
            if (!z) {
                this.ॱˎ = false;
            }
            if (this.ˋॱ == 1 || this.ˋॱ == 3) {
                this.ˏॱ = ॱॱ();
            }
        }
    }

    private boolean ˋ(byte b, byte b2) {
        boolean ॱॱ = ॱॱ(b);
        if (ॱॱ) {
            if (this.ॱˎ && this.ॱᐝ == b && this.ʻॱ == b2) {
                this.ॱˎ = false;
                return true;
            }
            this.ॱˎ = true;
            this.ॱᐝ = b;
            this.ʻॱ = b2;
        }
        if (ˊ(b, b2)) {
            ˋ(b2);
        } else if (ॱ(b, b2)) {
            ˏ(b, b2);
        } else if (ˎ(b, b2)) {
            this.ͺ.ˏ(b2 - 32);
        } else if (ᐝ(b, b2)) {
            ˏ(b2);
        }
        return ॱॱ;
    }

    private void ˋ(byte b) {
        boolean z = true;
        this.ͺ.ˏ(' ');
        if ((b & 1) != 1) {
            z = false;
        }
        this.ͺ.ˏ((b >> 1) & 7, z);
    }

    private void ˏ(byte b, byte b2) {
        boolean z;
        int i;
        int i2 = ˋ[b & 7];
        if (((b2 & 32) != 0 ? 1 : null) != null) {
            i2++;
        }
        if (i2 != this.ͺ.ˏ()) {
            if (!(this.ˋॱ == 1 || this.ͺ.ˎ())) {
                this.ͺ = new e(this.ˋॱ, this.ॱˋ);
                this.ˊॱ.add(this.ͺ);
            }
            this.ͺ.ˋ(i2);
        }
        Object obj = (b2 & 16) == 16 ? 1 : null;
        if ((b2 & 1) == 1) {
            z = true;
        } else {
            z = false;
        }
        int i3 = (b2 >> 1) & 7;
        e eVar = this.ͺ;
        if (obj != null) {
            i = 8;
        } else {
            i = i3;
        }
        eVar.ˏ(i, z);
        if (obj != null) {
            this.ͺ.ˎ(ˎ[i3]);
        }
    }

    private void ˏ(byte b) {
        switch (b) {
            case (byte) 32:
                ˏ(2);
                return;
            case (byte) 37:
                ˏ(1);
                ˎ(2);
                return;
            case (byte) 38:
                ˏ(1);
                ˎ(3);
                return;
            case (byte) 39:
                ˏ(1);
                ˎ(4);
                return;
            case (byte) 41:
                ˏ(3);
                return;
            default:
                if (this.ˋॱ != 0) {
                    switch (b) {
                        case (byte) 33:
                            this.ͺ.ˊ();
                            return;
                        case (byte) 36:
                            return;
                        case (byte) 44:
                            this.ˏॱ = Collections.emptyList();
                            if (this.ˋॱ == 1 || this.ˋॱ == 3) {
                                ˊॱ();
                                return;
                            }
                            return;
                        case (byte) 45:
                            if (this.ˋॱ == 1 && !this.ͺ.ˎ()) {
                                this.ͺ.ॱ();
                                return;
                            }
                            return;
                        case (byte) 46:
                            ˊॱ();
                            return;
                        case (byte) 47:
                            this.ˏॱ = ॱॱ();
                            ˊॱ();
                            return;
                        default:
                            return;
                    }
                }
                return;
        }
    }

    private List<Cue> ॱॱ() {
        List<Cue> arrayList = new ArrayList();
        for (int i = 0; i < this.ˊॱ.size(); i++) {
            Cue ʻ = ((e) this.ˊॱ.get(i)).ʻ();
            if (ʻ != null) {
                arrayList.add(ʻ);
            }
        }
        return arrayList;
    }

    private void ˏ(int i) {
        if (this.ˋॱ != i) {
            int i2 = this.ˋॱ;
            this.ˋॱ = i;
            ˊॱ();
            if (i2 == 3 || i == 1 || i == 0) {
                this.ˏॱ = Collections.emptyList();
            }
        }
    }

    private void ˎ(int i) {
        this.ॱˋ = i;
        this.ͺ.ˊ(i);
    }

    private void ˊॱ() {
        this.ͺ.ॱ(this.ˋॱ);
        this.ˊॱ.clear();
        this.ˊॱ.add(this.ͺ);
    }

    private static char ॱ(byte b) {
        return (char) ॱ[(b & 127) - 32];
    }

    private static char ˊ(byte b) {
        return (char) ˏ[b & 15];
    }

    private static char ˎ(byte b) {
        return (char) ʼ[b & 31];
    }

    private static char ʽ(byte b) {
        return (char) ʻ[b & 31];
    }

    private static boolean ˊ(byte b, byte b2) {
        return (b & 247) == 17 && (b2 & 240) == 32;
    }

    private static boolean ॱ(byte b, byte b2) {
        return (b & 240) == 16 && (b2 & 192) == 64;
    }

    private static boolean ˎ(byte b, byte b2) {
        return (b & 247) == 23 && b2 >= (byte) 33 && b2 <= (byte) 35;
    }

    private static boolean ᐝ(byte b, byte b2) {
        return (b & 247) == 20 && (b2 & 240) == 32;
    }

    private static boolean ॱॱ(byte b) {
        return (b & 240) == 16;
    }
}
